Ext.define('Admin.view.news.NewsForm', {
    extend: 'Admin.ux.form.FormPanel',
    xtype: 'news-form',
	title: '新闻信息发布',
    bodyStyle:'padding:5px 5px 5px 5px;',
    items: [
    	{	xtype:'hiddenfield',name:'id'},
        {
            layout: {
                type: 'column',
                border:false
            },
            items:[
                {
                    xtype: 'textfield',
                    name:'title',
                    readOnlyCls:'x-item-abled',
                    fieldLabel: '标题',
                    emptyText:'请输入标题[4-20位汉字]',
                    minLength:4,
                    maxLength:20,
                    labelWidth: 30,
                    columnWidth: .5,
                    //vtype:'alpha',
                    float: 'left'
                },
                {
                    xtype: 'textfield',
                    name:'source',
                    readOnlyCls:'x-item-abled',
                    fieldLabel: '来源',
                    columnWidth: .5,
                    labelWidth: 30,
                   // vtype:'alpha',
                    float: 'right'
                }
            ]
        },{
            layout: {
                type: 'column',
                border:false
            },
            items:[
                {
                    xtype: 'textfield',
                    name:'summary',
                    readOnlyCls:'x-item-abled',
                    fieldLabel: '内容摘要',
                    emptyText:'',
                    minLength:4,
                    maxLength:30,
                    labelWidth: 20,
                    columnWidth: .6,
                    //vtype:'alpha',
                    float: 'left'
                }
            ]
        },
        {
            layout: {
                type: 'column',
                border:false
            },
            items:[
                {
                    xtype: 'radiogroup',
                    fieldLabel: '是否轮播',
                    columns: 2,
                    columnWidth: .4,
                    items: [
                        {boxLabel: '轮播', name: 'IsCircle', inputValue: 0, checked: true},
                        {boxLabel: '不轮播', name: 'IsCircle', inputValue: 1}
                    ]
                },
                {
                    xtype: 'radiogroup',
                    fieldLabel: '是否置顶',
                    columnWidth: .4,
                    columns: 2,
                    items: [
                        {boxLabel: '置顶', name: 'IsTop', inputValue: 0, checked: true},
                        {boxLabel: '不置顶', name: 'IsTop', inputValue: 1}
                    ]
                }
            ]
        },
        {
            layout: {
                type: 'column',
                border:false
            },
            items:[
                {
                    xtype: 'tagfield',
                    fieldLabel: '类型',
                    emptyText:'全部',
                    displayField: 'type_name',
                    valueField: 'ChannelId',
                    queryMode: 'local',
                    minChars :1,
                    remoteFilter: true,
                    editable :true,
                    forceSelection :true,
                    filterPickList: true,
                    columnWidth: .6,
                    name:'ChannelId',
                    store: Ext.create('Ext.data.Store',{
                        fields: ['ChannelId','type_name'],
                        data: [
                            [1,'公司新闻'],
                            [2,'行业资讯'],
                            [3,'通知公告'],
                            [4,'政策法规'],
                            [5,'其他']
                        ],
                        autoLoad:true
                    })
                }
            ]
        },
        {
            fieldLabel: '内容',
            name: "content",
            xtype: 'kindeditor',
            anchor: '-20',
            height:800,
            kindeditorConfig: {
                //编辑器配置项
                uploadJson : '/upload/uploadFile', //上传文件服务器地址
                fileManagerJson : '/upload/fileManager', //文件管理服务器地址
                allowFileManager : false
            }
        },
        {
            xtype: 'button',
            text: '保存',
            ui: 'soft-green',
            iconCls: 'x-fa 	fa-floppy-o',
            listeners: {
                click: function(b,opts) {

                    var me = this;
                    var form = b.up("form").getForm();
                    var viewModel = me.getViewModel();
                    form.submit({
                        clientValidation: true,
                        url:'/news/add',
                        params:form.getFieldValues(),
                        success:function(form,action){
                            me.redirectTo('news-view', true);
                        },
                        failure:function(form,action){
                            switch (action.failureType) {
                                case Ext.form.action.Action.CLIENT_INVALID:
                                    Ext.create('Admin.ux.Action').error('客户端验证不通过');
                                    break;
                                default:
                                    viewModel.set("error",action.result.msg+"!");
                            }
                        }
                    });
                }
            }
        }
    ]
});